package com.ruoyi.electronicFence.service.Impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.electronicFence.domain.TDeviceStatus;
import com.ruoyi.electronicFence.domain.bo.TEfControllerBO;
import com.ruoyi.electronicFence.domain.TEfControllerVO;
import com.ruoyi.electronicFence.mapper.TDeviceStatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.electronicFence.mapper.TEfControllerMapper;
import com.ruoyi.electronicFence.domain.TEfController;
import com.ruoyi.electronicFence.service.ITEfControllerService;

/**
 * 控制器信息Service业务层处理
 *
 * @author sxygsj
 * @date 2024-06-11
 */
@Service
public class TEfControllerServiceImpl implements ITEfControllerService
{

    private final TEfControllerMapper tEfControllerMapper;
    private final TDeviceStatusMapper tDeviceStatusMapper;

    @Autowired
    public TEfControllerServiceImpl(TEfControllerMapper tEfControllerMapper, TDeviceStatusMapper tDeviceStatusMapper) {
        this.tEfControllerMapper = tEfControllerMapper;
        this.tDeviceStatusMapper = tDeviceStatusMapper;
    }
    /**
     * 查询控制器信息
     *
     * @param id 控制器信息主键
     * @return 控制器信息
     */
    @Override
    public TEfController selectTEfControllerById(Long id)
    {
        return tEfControllerMapper.selectTEfControllerById(id);
    }

    /**
     * 查询控制器信息列表
     *
     * @param tEfController 控制器信息
     * @return 控制器信息
     */
    @Override
    public List<TEfController> selectTEfControllerList(TEfController tEfController)
    {
        return tEfControllerMapper.selectTEfControllerList(tEfController);
    }

    /**
     * 新增控制器信息
     *
     * @param tEfController 控制器信息
     * @return 结果
     */
    @Override
    public int insertTEfController(TEfController tEfController)
    {
        return tEfControllerMapper.insertTEfController(tEfController);
    }

    /**
     * 修改控制器信息
     *
     * @param tEfController 控制器信息
     * @return 结果
     */
    @Override
    public int updateTEfController(TEfController tEfController)
    {
        return tEfControllerMapper.updateTEfController(tEfController);
    }

    /**
     * 批量删除控制器信息
     *
     * @param ids 需要删除的控制器信息主键
     * @return 结果
     */
    @Override
    public int deleteTEfControllerByIds(Long[] ids)
    {
        return tEfControllerMapper.deleteTEfControllerByIds(ids);
    }

    /**
     * 删除控制器信息信息
     *
     * @param id 控制器信息主键
     * @return 结果
     */
    @Override
    public int deleteTEfControllerById(Long id)
    {
        return tEfControllerMapper.deleteTEfControllerById(id);
    }

    @Override
    public List<TEfController> withDeviceInfoList(TEfControllerBO tEfControllerBO) {

        List<TEfController> tEfControllers = tEfControllerMapper.selectTEfControllerList((TEfController) tEfControllerBO);
        List< TEfControllerVO> list = new ArrayList<TEfControllerVO>();
        for (TEfController tEfController : tEfControllers ){
            TDeviceStatus deviceStatus = new TDeviceStatus();
            deviceStatus.setControllerCode(tEfController.getControllerCode());
            List<TDeviceStatus> tDeviceStatuses = tDeviceStatusMapper.selectTDeviceStatusList(deviceStatus);
            tEfController.setTDevices(tDeviceStatuses);
        }
        return tEfControllers;
    }
}
